<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>管理员设置</title>
		<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
		<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/5.12.1/css/all.min.css" >
		<link rel="stylesheet" type="text/css" href="/static/m.css" >
		<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
		<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
		<script src="/static/init.js?v=04"></script>
		<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>	
		<script src="/static/searchEdit.js"></script>
		<script>
		$.extend($.fn.validatebox.defaults.rules, {
			userName : {//验证用户名
				validator : function(value, param) {
					return /^[A-Za-z\u4E00-\u9FA50-9_@.]{2,15}$/.test(value);
				},
				message : '请输入2-15位字符，支持中英文、数字和下划线'
			},
		});
		</script>
	</head>
	<body>
		<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >页面加载中,请稍候...</div></div>
		<div class="easyui-layout" data-options="fit:true"  >
			<div data-options="region:'center'" >
				<table id="gridList" ></table>
			</div>
		</div>
		<div id="searchbar" >
			<div class="maction">
				<a href="javascript:void(0)" id="addButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-plus mbutton'">新增</a>
				<a href="javascript:void(0)" id="editButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-pencil-alt mbutton'">编辑</a>
				<a href="javascript:void(0)" id="removeButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-trash-alt mbutton color-c5'">删除</a>
				
				<!-- <a href="javascript:void(0)" id="authButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-user-tag mbutton'">角色设置</a> -->
				<!-- <a href="javascript:void(0)" id="resetpasswordButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-key mbutton'">重置密码</a> -->
				
				<a href="javascript:void(0)" id="btn5" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-user mbutton'">启用</a>
				<a href="javascript:void(0)" id="btn6" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-user mbutton color-c5'">禁用</a>
			</div>
			<!-- <form id="searchForm" >
				商户:<input id="search-company_id" name="company_id" class="easyui-textbox" >
				<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'fa fa-search mbutton'" >查询</a>
			</form> -->
		</div>

		<div id="dialog_1" >
			<div class="easyui-panel" data-options="fit:true,border:false" style="width:100%;">
				<form id="form-1"  data-options="novalidate:true" class="easyui-form container">
					<input type="hidden" name="id">
				      	<div style="margin-bottom:20px">
							<input class="easyui-textbox" name="username" style="width:100%" data-options="label:'用户名',required:true,validType:['userName']">
						</div>
				      <!-- <div class="col-md-6">
				      	<div style="margin-bottom:20px">
							<input class="easyui-textbox" name="nickname" style="width:100%" data-options="label:'姓名',required:true,validType:['userName']">
						</div>
				      </div> -->
				</form>
				<div style="text-align:center;padding:5px 0">
					<a href="javascript:void(0)" onclick="javascript:save()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-save mbutton'">保存</a>
					<a href="javascript:void(0)" onclick="javascript:cancel()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-times mbutton'">取消</a>
				</div>
			</div>
		</div>
	<div id="rolePanel" >
		<div class="easyui-layout" data-options="fit:true,border:false"  style="height:100%;width:100%;">
			<div data-options="region:'center',border:false" style="height:100%;width:100%;">
				<div data-options="fit:true,border:false" class="easyui-panel" title="" style="height:100%;width:100%;">
					<div id="roledatalist" title="" style="width:100%;height:90%" >
					</div>
				</div>
			</div>
			<div data-options="region:'south',border:false" style="text-align:center;height:55px;width:100%;padding-top:10px;">
				<a href="javascript:void(0)" onclick="javascript:saveRole()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-save mbutton'">保存</a>
				<a href="javascript:void(0)" onclick="javascript:closePanel()" class="easyui-linkbutton" data-options="plain:true,iconCls:'fas fa-times mbutton'">取消</a>
			</div>
		</div>
	</div>
	
	<script>
	//mask();
	var options={
			page_id:202,
			grid_id:"gridList",
			sqlname:"grid_202_sys_user_login",
			showCheckbox:false,
			rownumbers:false,
			gridParam:{sort:"id",order:"desc"}
		};
			//document ready
			$(function(){
				grid1=new uniontrip.datagrid.searchEdit(options);
				//初始化检索条件
				$('#addButton').bind('click', onAdd);//新增行绑定事件
				$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
				$('#authButton').bind('click', menuAuth);//角色设置绑定事件
				$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
				$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
				$('#editButton').bind('click',onEdit);//编辑按钮绑定事件
			    $('#removeButton').bind('click',onDelete);//删除行绑定事件
			    $('#btn5').bind('click',onEnable);//
			    $('#btn6').bind('click',onDisable);//
			    $('#searchButton').bind('click',grid1.load);//查询操作绑定事件
			    //$('#formCancelButton').bind('click', formCancelButton);
			    $('#showChangesButton').bind('click',grid1.showChanges);
			    $('#resetpasswordButton').bind('click', resetpasswordButton);//重置密码绑定事件
			    $('#search-sql_name').textbox().textbox('addClearBtn', 'icon-clear');
			    
			    
			    
			    dialogHeight=windowHeight*0.6;
				$('#dialog_1').dialog({
					title:"新增账号",
					cls:"miframePanel",
					width:'400px',
					height:dialogHeight,
					modal:true,
					closed:true,
					maximizable:true,
					onClose:function(){
						//grid1.load();
					},
					/* buttons: [{
						text:'保存',
						iconCls:'icon-ok',
						handler:function(){
							alert('ok');
						}
					},{
						text:'取消',
						handler:function(){
							alert('cancel');;
						}
					}] */
				});
				
				$('#rolePanel').dialog({
					title:"角色设置",
					cls:"miframePanel",
					width:'300px',
					height:dialogHeight,
					modal:true,
					closed:true,
					maximizable:true,
					onClose:function(){
						//grid1.load();
					},
					/* buttons: [{
						text:'保存',
						iconCls:'icon-ok',
						handler:function(){
							alert('ok');
						}
					},{
						text:'取消',
						handler:function(){
							alert('cancel');;
						}
					}] */
				});
			});

			/**
			 * 新增一行
			 */
		    function openDailog(){
		    	$('#dialog_1').dialog('open');
		    }
		function save(){
			//var regExp = /^[A-Za-z_@.]{6,15}$/;
			if($("#form-1").form('enableValidation').form('validate')){
				var formObject=$("#form-1").serializeObject();
				$.post("/authenticated/userLogin/save",JSON.stringify(formObject),function(result){
					if(result.success){
						$.messager.alert("提示", "保存成功！");
						grid1.load();
						$('#dialog_1').dialog("close");
					}else{
						$.messager.alert("提示", "保存失败！\n"+result.message);
					}
				});
			}
		}
		function cancel(){
			$('#dialog_1').dialog("close");
		}
		/**
		编辑
		*/
		function onEdit(){
			gridSelectRow(grid1.grid,function(row){
				//console.log(row);
				$('#dialog_1').dialog('setTitle','编辑账号信息').dialog('open');
				$("#form-1").form('load',row);
			});
		}
		function onAdd(){
				$('#dialog_1').dialog('setTitle','新增账号').dialog('open');
				$("#form-1").form('clear');
		}
		/**
	     * 重置密码
	     */
	    function resetpasswordButton(){
	    	var selectRows=grid1.grid.datagrid('getSelections');
	    	var checkArray=new Array();
			if(selectRows.length>0){
				$.each(selectRows,function(i,v){
		    		checkArray.push(v.id);
				});
				$.ajax({
					type: "post",
					contentType:"application/json",
		    		url: "/authenticated/user/password",
		    		data:JSON.stringify({ids:checkArray}),
		    		dataType:"json",
		    		success: function(result){
		    			if(result.success){
		    				$.messager.show({
		    					title:'提示',
		    					msg:'重置密码成功！',
		    					timeout:1000,
		    					showType:'fade',
		    					style:{
		    						right:'',
		    						top:document.body.scrollTop+document.documentElement.scrollTop,
		    						bottom:''
		    					}
		    				});
		    			}else{
		    				$.messager.alert("提示", "重置密码失败！<br>"+result.message);
		    			}
		    		},
		    		error: function(){
		    			$.messager.alert("提示", "请求失败！");
		    		}
		    	});
			}else{
				info('请选择一条数据！');
			}
	    }
		
		function onEnable(){
			var selectRows=grid1.grid.datagrid('getSelections');
			if(selectRows.length>0){
				selectRowid=selectRows[0].id;
				$.post("/authenticated/userLogin/enable",JSON.stringify({ids:selectRowid}),function(result){
					if(result.success){
	    				grid1.load();
	    			}else{
	    				$.messager.alert("提示", "操作失败！<br>"+result.message);
	    			}
				});
			}else{
				info('请选择一条数据！');
			}
		}
		function onDisable(){
			var selectRows=grid1.grid.datagrid('getSelections');
			if(selectRows.length>0){
				selectRowid=selectRows[0].id;
				$.post("/authenticated/userLogin/disable",JSON.stringify({ids:selectRowid}),function(result){
					if(result.success){
	    				grid1.load();
	    			}else{
	    				$.messager.alert("提示", "操作失败！<br>"+result.message);
	    			}
				});
			}else{
				info('请选择一条数据！');
			}
		}
	    /**
	     * 删除
	     */
		function onDelete(){
			gridConfirm(grid1.grid,"是否确认删除",function(selectRow){
				$.post("/authenticated/userLogin/delete",JSON.stringify({ids:selectRow.id}),function(result){
					if(result.success){
	    				grid1.load();
	    			}else{
	    				$.messager.alert("提示", "删除失败！<br>"+result.message);
	    			}
				});
			});
		}
	    /**
	     * 角色设置
	     */
	    function menuAuth(){
	    	var selectRows=grid1.grid.datagrid('getSelections');
			if(selectRows.length>0){
				selectRowid=selectRows[0].id;
				var roledata;
				$.ajax({
					type: "post",
					contentType:"application/json",
		    		url: "/authenticated/ajax/select_user_role_br_ulid",
		    		data:JSON.stringify({id:selectRowid}),
		    		dataType:"json",
		    		success: function(result){
		    			if(result.success){
		    				roledata=result.data;
		    				$('#roledatalist').datalist({
		    					checkbox: true,
		    					singleSelect:false,
		    					valueField:'id',
		    					textField:'role_name',
		    					data:roledata
		    				});
		    				$.each(roledata,function(i,v){
		    					if(v.checked=="true"){
		    						$('#roledatalist').datalist("checkRow",i);
		    					}
		    				});
		    			}else{
		    				$.messager.alert("提示", "查询角色信息失败！<br>"+result.message);
		    			}
		    		},
		    		error: function(){
		    			$.messager.alert("提示", "请求失败！");
		    		}
		    	});
				$('#rolePanel').dialog('open');
			}else{
				info('请选择一条数据！');
			}
	    }
	    function closePanel(){
			$('#rolePanel').dialog('close');
		}
	    function saveRole(){
	    	var checkedRows=$('#roledatalist').datalist('getChecked');
	    	var checkArray=new Array();
	    	$.each(checkedRows,function(i,v){
	    		checkArray.push(v.id);
			});
	    	
	    	var param={"user_id":selectRowid,"roleids":checkArray};
	    	$.ajax({
	    		type: "post",
	    		contentType:"application/json",
	    		url: "/authenticated/userrole",
	    		data:JSON.stringify(param),
	    		dataType:"json",
	    		success: function(result){
	    			if(result.success){
	    				$.messager.alert("提示", "授权成功！");
	    				closePanel();
	    			}else{
	    				$.messager.alert("提示", "授权失败！<br>"+result.message);
	    			}
	    		},
	    		error: function(){
	    			$.messager.alert("提示", "请求失败！");
	    		}
	    	});
	    	
	    	selectRowid=undefined;
	    }
	</script>
	</body>
</html>
